<template>
  <div>
    <el-dialog
      title="修改禁用状态"
      :visible.sync="dialogVisible"
      width="16%"
      append-to-body
      class="dialog-box"
      :close-on-click-modal="false"
    >
      <el-select v-model="durationHour" placeholder="请选择" style="width: 100%;">
        <el-option
          v-for="item in disableDict"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button v-loading="submitLoading" type="primary" @click="submit">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import { cancelDisableState, teacherSetDisableState } from '@/api/sdutent/Stulist'

export default {
  name: 'SetDisable',
  data() {
    return {
      submitLoading: false,
      dialogVisible: false,
      disableDict: [
        { value: 0, label: '不禁用' },
        { value: 168, label: '一周' },
        { value: 336, label: '二周' },
        { value: 504, label: '三周' },
        { value: 672, label: '四周' }
      ],
      durationHour: 0,
      studentId: ''
    }
  },
  methods: {
    open(item) {
      console.log(item)
      this.studentId = item.studentid
      this.durationHour = 0
      this.dialogVisible = true
    },
    submit() {
      const data = {
        studentId: this.studentId
      }
      if (this.durationHour) {
        data.durationHour = this.durationHour
      }
      this.submitLoading = true;
      (this.durationHour === 0 ? cancelDisableState : teacherSetDisableState)(data).then(res => {
        this.submitLoading = false
        if (res.code === 200) {
          this.$message.success('操作成功')
          this.dialogVisible = false
          this.$emit('submit')
        }
      }).catch(() => { this.submitLoading = false })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
